/*
 * Copyright (C), 2010-2017, ATCOM Tech. Co., Ltd.
 *
 * File Name: threadlog.c
 * Author: liaoxuecheng
 * mail: 872958436@qq.com
 * Created Time: Thu 03 Sep 2020 10:14:51 AM CST
 *
 */

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>

#include "threadlog.h"

static int log_type = 0;
static int log_level = 0;

int threadpool_log_set_level(int level)
{
    log_level = level;
}

int threadpool_log_init(const char *name, int type, int level)
{
    openlog(name, LOG_CONS | LOG_PID, 0);
    log_type = type;
    log_level = level;
    return 0;
}

int threadpool_log_deinit()
{
    closelog();
}

int threadpool_log(int priority, const char *format, ...)
{
    if(log_level < priority)
        return 0;

    int result = 0;

    va_list vp;
    va_start(vp, format);
    if(log_type == LOG_SYSLOG)
    {
        vsyslog(priority, format, vp);
    }
    else
    {
        result = vprintf(format, vp);
    }
    return result;
}
